package com.doeis.uwork.dao;

import java.util.List;

import com.doeis.uwork.entity.mongo.OffPacket;
import com.google.inject.Singleton;
import com.mongodb.BasicDBObject;
import com.mongodb.util.JSON;
import com.voland.core.db.DaoException;
import com.voland.core.db.MongoDao;

@Singleton
public class OffPacketMongoDao extends MongoDao {
	/**
	 * 获取每个人的离线消息
	 * @param myswitchbaord
	 * @param userid
	 */
	public List<OffPacket> findOffPacket(String myswitchbaord, String userId)throws DaoException{
		try{
			StringBuffer con = new StringBuffer(" { userId:\""+userId+"\" }   ");
			BasicDBObject query = (BasicDBObject)JSON.parse(con.toString());	
			BasicDBObject sort = new BasicDBObject();
			sort.put("created_at", 1);
			return super.query(myswitchbaord, OffPacket.class, query, sort);
		}catch(Exception e){
			throw new DaoException(e);
		}
	}
	
	/**
	 * 根据bodyid获取离线信息，然后进行处理
	 * @param userid
	 */
	public List<OffPacket> findOffPacketBybodyid(String myswitchbaord, String bodyid, String userId)throws DaoException{
		try{
			StringBuffer con = new StringBuffer(" { bodyid:\""+bodyid+"\", userId:\""+userId+"\" }   ");
			BasicDBObject query = (BasicDBObject)JSON.parse(con.toString());	
			BasicDBObject sort = new BasicDBObject();
			sort.put("created_at", 1);
			return super.query(myswitchbaord, OffPacket.class, query, sort);
		}catch(Exception e){
			throw new DaoException(e);
		}
	}
}
